package com.zhkj.txg.module.mine.adapter

import android.view.View
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.txg.R
import com.zhkj.txg.module.mine.entity.ProblemEntity


class ProblemAdapter : BaseQuickAdapter<ProblemEntity, BaseViewHolder>(R.layout.item_problem_text) {


    init {
        setOnItemClickListener { adapter, view, position ->
            val webProblemContent: WebView = adapter.getViewByPosition(position, R.id.webProblemContent) as WebView

            val webSettings: WebSettings = webProblemContent.getSettings()
            webSettings.displayZoomControls = false //隐藏webview缩放按钮
            webSettings.javaScriptEnabled = true //支持js
            webProblemContent.webViewClient = object : WebViewClient() {
                override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
                    // 得到 URL 可以传给应用中的某个 WebView 页面加载显示
                    return true
                }
            }
            webProblemContent.loadDataWithBaseURL(null, data[position].content, "text/html", "UTF-8", null);

            if (webProblemContent.visibility == View.VISIBLE) {
                webProblemContent.visibility = View.GONE
            } else {
                webProblemContent.visibility = View.VISIBLE
            }
        }
    }

    override fun convert(helper: BaseViewHolder, item: ProblemEntity) {
        helper.setText(R.id.tvProblemTitle, item.title)
    }

}